﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


public partial class index : System.Web.UI.Page
{
    //Different views that index will show
    protected enum Viewerstate
    {
        index,
        no_password,
        loggedIn,

    }
    //The viewerstate that user is on
    protected Viewerstate m_viewerstate;     
    
    protected void Page_Load(object sender, EventArgs e)
    {       
        //1. Check if logged in
        //  1.1 Set viewerstate to loggedIn
        //2. Check if Loginfile Exists
        //  2.1 Viewerstate = no_password
        //3. Otherwise loginscreen
        

        if (LoginHandler.IsLoggedIn( Session ) )
        {            
            m_viewerstate = Viewerstate.loggedIn;
        }
        else if (!LoginHandler.FileExists())
        {            
            m_viewerstate = Viewerstate.no_password;
        }
        else
        {
            m_viewerstate = Viewerstate.index;
        }

        switch (m_viewerstate)
        {
            case Viewerstate.loggedIn:
                index_content.Controls.Add(Page.LoadControl(Paths.admin_uc_loggedin));
                break;
            case Viewerstate.no_password:
                index_content.Controls.Add(Page.LoadControl(Paths.admin_uc_createCredentials));
                break;
            case Viewerstate.index:
                index_content.Controls.Add(Page.LoadControl(Paths.admin_uc_loginControl));
                break;
        }
    }    
}